package com.factory._11strategy.strategy;

import com.factory._11strategy.entity.PayWayEnum;
import com.factory._11strategy.strategyimp.AliPayStrategy;
import com.factory._11strategy.strategyimp.CardPayStrategy;
import com.factory._11strategy.strategyimp.WecatPayStrategy;

import java.util.HashMap;

/**
 * @author Qinye
 * @date 2023/8/13 13:25
 */
public class PayStrategyFactory {
    private PayStrategyFactory() {
    }

    private static HashMap<Integer, PayStrategy> payStrategyHashMap = new HashMap<>();
    private static PayStrategyFactory payStrategyFactory = new PayStrategyFactory();

    static {
        payStrategyHashMap.put(PayWayEnum.ALI.getCode(), new AliPayStrategy());
        payStrategyHashMap.put(PayWayEnum.WECHAT.getCode(), new WecatPayStrategy());
        payStrategyHashMap.put(PayWayEnum.CARD.getCode(), new CardPayStrategy());
        payStrategyHashMap.put(PayWayEnum.CASH.getCode(), new CardPayStrategy());
    }

    public static PayStrategyFactory getInstance() {
        return payStrategyFactory;
    }

    public  PayStrategy select(Integer payCode) {
        return payStrategyHashMap.get(payCode);
    }
}
